package engine.newUi
{
	import engine.data.ModelLocator;
	import engine.data.ResPath;
	import engine.logic.walk.WalkManager;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.ui.lite.BaseUI;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.control.button.NxButton;
	import newx.com.control.text.NxLabel;
	
	public class BoxBuffUI extends BaseUI
	{
		public var back1:MovieClip;
		public var back2:MovieClip;
		public var okBtn:NxButton;
		public var desLabel:NxLabel;
		public var buffImage:NxClip;
		
		private static var self:BoxBuffUI;
		private var model:ModelLocator;
		
		public function BoxBuffUI(popupUI:Boolean=true)
		{
			super(popupUI);
		}
		
		public static function getInstance():BoxBuffUI
		{
			if(self == null)
			{
				self	=	new BoxBuffUI();
			}
			return self;
		}
		
		override public function Init():void
		{
			model	=	ModelLocator.getInstance();
			model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_FORBIDDEN_AREA_OPEN_BOX),showInfo);
		}
		
		override protected function BeforeShow():void
		{
			addEvents();
		}
		
		override protected function AfterHide():void
		{
			removeEvents();
			
			WalkManager.getInstance().walkLogic.isReset	=	false;
		}
		
		private function addEvents():void
		{
			okBtn.addEventListener(MouseEvent.CLICK,onClick);
		}
		
		private function removeEvents():void
		{
			okBtn.removeEventListener(MouseEvent.CLICK,onClick);
		}
		
		
		private function showInfo(e:CustomMsgEvent):void
		{
			show();
			desLabel.htmlText	=	"";
			var arr:Array		=	e.pList;
//			buffImage.source	=	ResPath.PNG+arr[0]+".png";
//			arr.splice(0,1);
			desLabel.htmlText	= StaticIni.getSwfLangStrVar("Des_"+arr[0],checkState());
			
			function checkState():Array
			{
				if(arr[1] !=0 ) return [ StaticIni.getSwfLangStr("BufferDes_"+arr[1]) ];
				if(arr[2] !=0 ) return [ StaticIni.getSwfLangStrVar("ForbiddenAreaStr_11",[ arr[2] ]) ];
				arr.splice(0,3);
				var length:int	=	arr.length;
				var str:String	=	"";
				for(var i:int=0;i<length;i++)
				{
					str	+=	StaticIni.getSwfLangStr(arr[i]) + " ";
				}
				return [str];
			}
		}
		
		private function onClick(e:MouseEvent):void
		{
			hide();
		}
		
		
	}
}